import jQuery from "jquery";
import window from '../../util';
import { WeaLocaleProvider, WeaTools} from 'ecCom';
import { listStore, SearchDisplayType } from '../../stores/list';
import { Menu,  Button } from 'antd';
import _ from 'lodash';
import load from 'loadjs';
import { getUrlParams } from '../../util/typeUtil';
import * as React from "react";

const getLabel = WeaLocaleProvider.getLabel;
const MenuItem = Menu.Item;

/*****componentDidMount 后的一些绑定计算处理 */
export const renderSearchAdPanel = (Search) => {
    //窗口变化后，重新计算高级搜索的面板位置。如果查询条件默认展开，使用默认位置，不计算。
    if (!Search.isShowCondition) {
        try {
            const hei = jQuery('.cube-list-wrapper .wea-tab .ant-row').height() || 46;
            jQuery('.cube-list-wrapper .wea-tab .wea-search-container ').css({ top: hei });
        } catch (e) {
        }
    }
};
export const componentComputed = (Search, computeTableHeight) => {
    const renderMaskDark = () => {
        //窗口变化后，重新计算高级搜索的遮盖蒙版
        try {
            const searchContainer = jQuery('.cube-list-wrapper .wea-search-container');
            if (searchContainer.length) {
                const pos_top = searchContainer.eq(0).position().top + searchContainer.eq(0).height();
                jQuery('.cube-list-wrapper .wea-tab.wea-tab-search-ad').css({ position: 'static' }).find('.mask-dark').css({
                    top: pos_top,
                    bottom: 0,
                    height: 'auto'
                })
            }
        } catch (e) {
        }
    }
    window.addEventListener('resize', function () {
        window['computeTableHeight']();
        const { quickSearchData } = Search;
        const { quicksearchinfo = [] } = quickSearchData;
        if (quicksearchinfo.length && !Search.isShowCondition) {
            renderSearchAdPanel(Search);
            renderMaskDark();
        }
    })

    window['openSlideModalDel'] = (flg, url, sliderPercentage) => {
        Search.showSlideModal(flg, url, sliderPercentage);
        window._table.reLoad();
    }

    window['dosubmitfun'] = () => {
        Search.dosubmitfun();
    }

    window['removeStatusIconForMode'] = (flg, billid) => {
        if (flg) jQuery(`.statusiconformmode_${billid}`).hide();
    }

    window['slideflgfun'] = () => {
        return Search.slideflg;
    }
    window['openSlideModal'] = (flg, url, sliderPercentage) => {
        Search.showSlideModal(flg, url, sliderPercentage);
    }

    jQuery('.coms-mode-docker').delegate('.mask-wrapper', 'click', () => {
        Search.condition.update({ visible: false });
    });

    setTimeout(() => {
        let { quickSearchData } = Search;
        if (!_.isEmpty(quickSearchData.quicksearchinfo)) {
            /***有快捷搜索的时候计算下weatab的高度，方便展开蒙层 */
            if (!Search.isShowCondition) {
                renderSearchAdPanel(Search);
            } else {
                computeTableHeight && computeTableHeight(Search);
            }
        }
    }, 2500);

    window['computeTableHeight'] = () => {
        if (jQuery('.cube-mobx-table-tbody-tr-td-lk')[0]) {
            if (jQuery(jQuery('.cube-mobx-table-tbody-tr-td-lk')[0]).find('.cube-table-body')[0]) {
                jQuery(jQuery('.cube-mobx-table-tbody-tr-td-lk')[0]).find('.cube-table-body')[0].style.maxHeight = (document.body.offsetHeight - jQuery(jQuery('.cube-mobx-table-tbody-tr-td-lk').eq(0).find('.cube-table-body')[0]).offset().top - 90) + 'px';
            }
        }
    }

    window.perfectHeight = () => {
        if (!Search.newTable.loading) {
            const topHeight = jQuery('.wea-new-top-wapper').find('.wea-new-top').height() || 0;
            const tabHeight = jQuery('.wea-new-top-wapper').find('.wea-new-top-content').find('.wea-tab').height() || 0;
            const countHeight = jQuery('.wea-new-top-wapper').find('.cube-list-countContainer').height() || 0;
            if (Search.displayType === SearchDisplayType.ImgType) { //图片看板
                const imgDivHeight = jQuery('.wea-new-top-wapper').find('.imgTypeDiv-tableCol-innerHtml').height() || 0;
                return imgDivHeight + topHeight + tabHeight + countHeight + 375;
            } else if (Search.displayType === SearchDisplayType.VerticalType) {
                const listHeight = jQuery('.wea-new-top-wapper').find('.cube-vertical-list').height() || 0;
                return listHeight + topHeight + tabHeight + countHeight + 375;
            } else if (Search.displayType === SearchDisplayType.Excel) { //excel
                const excelDivHeight = jQuery('.wea-new-top-wapper').find('.cube-excel-list').height() || 0;
                if (excelDivHeight > 375) {
                    return
                }
                return excelDivHeight + topHeight + tabHeight + countHeight + 375;
            } else {
                let bodyScrollHeight = jQuery('.coms-mode-search').find('.cube-list-table').find('.ant-table-scroll').find('.ant-table-body').prop('scrollHeight');
                bodyScrollHeight = bodyScrollHeight ? bodyScrollHeight : jQuery('.cube-mobx-table-tbody-tr-td-lk .cube-table-body').height();
                return bodyScrollHeight + topHeight + tabHeight + countHeight + 375;
                //考虑到数据没有的时候高级搜索不显示完全。设置375吧最低
            }
        }
    }

    /**挂载地图显示方法 */
    window.showFormModeMap = (fieldvalue) => {
        Search.showCubeMap(true, fieldvalue);
    }
    !load.isDefined('imcarouselJS') && load(
        [
            '/social/js/drageasy/drageasy.js',
            '/social/js/bootstrap/js/bootstrap.js',
            '/social/im/js/IMUtil_wev8.js',
            '/social/js/imcarousel/imcarousel.js',
        ],
        'imcarouselJS');
    /**
     *  处理列表兼容火狐
     */
    let htmlObj: any = document.documentElement;
    htmlObj.setAttribute('data-useragent', navigator.userAgent);
    htmlObj.setAttribute('data-platform', navigator.platform);

}


/****自定义mobxtable的操作按钮 */
export const customOperates = (record, index, operates, Search) => {
    const itemsArr: any = [];
    let operatesshow = record.operatesshowspan || '';
    let likestatus = record.likesinfospan && record.likesinfospan.split(',')[2] ? record.likesinfospan.split(',')[2] : '';
    let likecount = record.likesinfospan && record.likesinfospan.split(',')[0] ? record.likesinfospan.split(',')[0] : '0';
    let dislikecount = record.likesinfospan && record.likesinfospan.split(',')[1] ? record.likesinfospan.split(',')[1] : '0';
    const isExitIcon = isExitIconHandle('customOpt', operates, operatesshow);
    operates.map(function (value, index1, array) {
        //判断自定义按钮权限
        if (operatesshow.split('+')[index1] && operatesshow.split('+')[index1] == 'true') {
            if (array[index1].nodeName && array[index1].nodeName == 'operate') {
                if (array[index1].href == 'javascript:likes') {
                    let classname = 'icon-coms02-like-o';
                    let titlename = array[index1].text;
                    let key = '1';
                    if (likestatus == '1') {
                        classname = 'icon-coms02-like';
                        titlename = getLabel('31129', '取消') + array[index1].text;
                        key = '0';
                    }
                    itemsArr.push(<MenuItem>
                        <a href="javascript:void(0);"
                           onClick={() => {
                               Search.likeOrDislike(record, key, index, '0');
                           }}
                        >
                            <i title={titlename} className={classname}/>
                            {' ' + array[index1].text + ' (' + likecount + ')'}
                        </a>
                    </MenuItem>);
                } else if (array[index1].href == 'javascript:dislikes') {
                    let classname = 'icon-coms02-Negative-comment-o';
                    let titlename = array[index1].text;
                    let key = '2';
                    if (likestatus == '2') {
                        classname = 'icon-coms02-Negative-comment';
                        titlename = getLabel('31129', '取消') + array[index1].text;
                        key = '0';
                    }
                    itemsArr.push(<MenuItem>
                        <a href="javascript:void(0);"
                           onClick={() => {
                               Search.likeOrDislike(record, key, index, '0');
                           }}
                        >
                            <i title={titlename} className={classname}/>
                            {' ' + array[index1].text + ' (' + dislikecount + ')'}
                        </a>
                    </MenuItem>);
                } else {
                    itemsArr.push(<MenuItem>
                        <a href="javascript:void(0);"
                           onClick={() => {
                               Search.doCustomButton(record, '', array[index1], '');
                           }}
                        >
                            {isExitIcon ? <div className='cube-list-icon-box'>{array[index1].icon?<img src={array[index1].icon}/>:''}</div> : ''}
                            {array[index1].text}
                        </a>
                    </MenuItem>);
                }
            }
        }
    })
    return (
        <Menu>
            {itemsArr}
        </Menu>
    );
};


/*****
 * 计算列表数据区域高度
 */
let timeCounter: any;
export const getHeight = (Search: listStore) => {
    const { ImgType, VerticalType } = SearchDisplayType;
    timeCounter = setTimeout(() => {
        const newTable = jQuery('.cube-list-wrapper .wea-new-table');
        if (newTable && newTable.children().length) {
            clearTimeout(timeCounter);
            const urlParams = getUrlParams();
            const { displayType = '' } = urlParams;
            const noData: boolean = !(Search.datalist.length > 0);
            try {
                if (displayType == "treeType" || Search.displayType == 'treeType') {
                    const pageHeight = jQuery('.ant-pagination').height();
                    const paginationHeight = pageHeight ? pageHeight + 32 : 46;
                    const headerHeight = jQuery('.ant-table-header').height() || 32;
                    const mxheight = jQuery('body').height() - jQuery('.cube-list-table').offset().top - headerHeight - paginationHeight;
                    const minHeight = noData ? 0 : 100;
                    if (mxheight < minHeight) {
                        jQuery('.wea-new-top-content').css("overflow-y", "auto");
                        jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('minHeight', minHeight);
                    } else {
                        jQuery(".wea-new-top-content").scrollTop(0, 0)
                        jQuery('.wea-new-top-content').css("overflow-y", "hidden");
                        jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('minHeight', 'auto');
                    }
                    mxheight && jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('maxHeight', mxheight < minHeight ? minHeight : mxheight);

                } else if (Search.displayType == VerticalType) { //列表右侧出现纵向列表
                    let preClassName = '';
                    const isFromCard = jQuery('.coms-mode-card').length > 0; // 查询列表作为卡片的页面扩展 内嵌或者外嵌 高度计算出错
                    if (isFromCard) {
                        preClassName = jQuery('.cube-card-content').css('display') == 'inline' ? '.cube-card-content' : '.cube-toptab-container';
                    }
                    let mxheight = jQuery('body').height() - jQuery(`.cube-rightleft-layout-right ${preClassName} .cube-vertical-list`).offset().top - 20;
                    const listH = mxheight < 100 ? 100 : mxheight;
                    jQuery('.cube-rightleft-layout-right .cube-vertical-list').css('height', listH);
                    const listItemsH = jQuery('.cube-rightleft-layout-right .cube-vertical-list .vertical-list-items').height();
                    if (listItemsH > listH) {
                        jQuery('.cube-rightleft-layout-right .cube-vertical-list .cube-vertical-list-loadingmore').hide();
                    } else {
                        jQuery('.cube-rightleft-layout-right .cube-vertical-list .cube-vertical-list-loadingmore').show();
                    }
                } else if (displayType != "excel") {
                    let preClassName = '';
                    const isFromCard = jQuery('.coms-mode-card').length > 0; // 查询列表作为卡片的页面扩展 内嵌或者外嵌 高度计算出错
                    if (isFromCard) {
                        preClassName = jQuery('.cube-card-content').css('display') == 'inline' ? '.cube-card-content' : '.cube-toptab-container';
                    }
                    const paginationHeight = jQuery(`${preClassName} .wea-table-pagination`).height() || 44;
                    const headerHeight = jQuery(`${preClassName} .ant-table-header`).height() || 41;
                    const mxheight = jQuery('body').height() - jQuery(`${preClassName} .wea-new-table.cube-list-table`).offset().top - headerHeight - paginationHeight - 5;
                    const minHeight = noData ? 0 : 100;//table上面内容太多，会导致table数据不显示
                    if (mxheight < minHeight) {
                        jQuery('.wea-new-top-content').css("overflow-y", "auto");//内容过多时，给table最小高度同时外部添加滚动。
                        jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('minHeight', minHeight);
                    } else {
                        jQuery(".wea-new-top-content").scrollTop(0, 0)
                        jQuery('.wea-new-top-content').css("overflow-y", "hidden");
                        jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('minHeight', 'auto');
                    }
                    mxheight && jQuery('.cube-list-wrapper .cube-list-table .ant-table-body').css('maxHeight', mxheight < minHeight ? minHeight : mxheight);
                }
            } catch (e) {
            }
        } else if (Search.displayType == ImgType || Search.displayType == VerticalType) {
            /***
             * 在相册基础上计算下数据展示区域的高度
             */
            try {
                let preClassName = '';
                const isFromCard = jQuery('.coms-mode-card').length > 0; // 查询列表作为卡片的页面扩展 内嵌或者外嵌 高度计算出错
                if (isFromCard) {
                    preClassName = jQuery('.cube-card-content').css('display') == 'inline' ? '.cube-card-content' : '.cube-toptab-container';
                }
                const paginationHeight = jQuery(`${preClassName} .wea-table-pagination`).height() || 44;
                const headerHeight = jQuery(`${preClassName} .ant-table-header`).height() || 41;
                if (Search.displayType == ImgType) {
                    let mxheight = jQuery('body').height() - jQuery(`${preClassName} .imgTypeDiv-tableCol-innerHtml`).offset().top - headerHeight - paginationHeight - 20;
                    const minHeight = 100;//table上面内容太多，会导致table数据不显示
                    const imgH = mxheight < minHeight ? minHeight : mxheight;
                    jQuery('.imgTypeDiv-tableCol-innerHtml').css('maxHeight', imgH);
                    if (jQuery('.imgTypeDiv-tableCol-innerHtml').height() == imgH) {
                        clearTimeout(timeCounter);
                    }

                }

                if (Search.displayType == VerticalType) {
                    let mxheight = jQuery('body').height() - jQuery(`${preClassName} .cube-vertical-list`).offset().top - 20;
                    const listH = mxheight < 100 ? 100 : mxheight;
                    jQuery(`${preClassName} .cube-vertical-list`).css('height', listH);
                    const listItemsH = jQuery('.cube-vertical-list .vertical-list-items').height();
                    if (jQuery(`${preClassName} .cube-vertical-list`).height() == listH) {
                        clearTimeout(timeCounter);
                    }
                    if (listItemsH > listH) {
                        jQuery('.cube-vertical-list .cube-vertical-list-loadingmore').hide();
                    } else {
                        jQuery('.cube-vertical-list .cube-vertical-list-loadingmore').show();
                    }

                }
            } catch (e) {
            }
        } else if (Search.displayType == 'excel') {
            const paginationHeight = jQuery('.ant-pagination').height() + 20 || 46;
            if (jQuery("#excelDiv") && jQuery("#excelDiv").offset()) {
                const mxheight = jQuery('body').height() - jQuery("#excelDiv").offset().top - paginationHeight;
                if (jQuery('#excelDiv').height() == mxheight) {
                    clearTimeout(timeCounter);
                }
                jQuery('#excelDiv').height(mxheight);
            }
        } else {
            if (timeCounter < 20000) {
                getHeight(Search);
            } else {
                clearTimeout(timeCounter);
            }
        }
    }, 200)
};


/*****
 * 处理自定义按钮的，之前没有公用，我写纵向列表的时候提出来，后面看下能不能别的也走这里的逻辑 -- ljc
 * Search:liststore
 * ,type: 点赞的type列表类型 1 :normal, 0 :imgtype, 2:分组列表，5：纵向列表
 */
export const parserColumnsForFunc = (record, num, cb, index, Search, type, isExitIcon) => {
    let otherparas = cb.otherpara.split("+");
    let index1 = 0;
    for (index1; index1 < otherparas.length; index1++) {
        let islikebutton = otherparas[index1].replace("#islikebutton:", "");
        if (islikebutton && islikebutton == '1') {
            let likeinfo = otherparas[index1 + 1].replace("#likeinfo:", "")
            let likecount = likeinfo.split(",")[1];
            let dislikecount = likeinfo.split(",")[2];
            let type = likeinfo.split(",")[0];
            let status = likeinfo.split(",")[3];
            if (type == '5') {
                if (status == '1') {
                    return <MenuItem>
                        <span
                            onClick={() => {
                                Search.likeOrDislike(record, "0", index, type);
                            }}
                        >
                            <span><i title={getLabel('31129', '取消') + cb.text} className={"icon-coms02-like"}/><span
                                style={{ color: '#000' }}>{' ' + cb.text + '(' + likecount + ')'}</span></span>
                        </span>
                    </MenuItem>;
                } else {
                    return <MenuItem>
                        <span
                            onClick={() => {
                                Search.likeOrDislike(record, "1", index, type);
                            }}
                        >
                            <span><i title={cb.text} className={"icon-coms02-like-o"}/><span
                                style={{ color: '#000' }}>{' ' + cb.text + ' (' + likecount + ')'}</span></span>
                        </span>
                    </MenuItem>;
                }
            } else if (type == '6') {
                if (status == '2') {
                    return <MenuItem>
                        <span
                            onClick={() => {
                                Search.likeOrDislike(record, "0", index, type);
                            }}
                        >
                            <span><i title={getLabel('31129', '取消') + cb.text}
                                     className={"icon-coms02-Negative-comment"}/><span
                                style={{ color: '#000' }}>{' ' + cb.text + ' (' + dislikecount + ')'}</span></span>
                        </span>
                    </MenuItem>;
                } else {
                    return <MenuItem>
                        <span
                            onClick={() => {
                                Search.likeOrDislike(record, "2", index, type);
                            }}
                        >
                            <span><i title={cb.text} className={"icon-coms02-Negative-comment-o"}/><span
                                style={{ color: '#000' }}>{' ' + cb.text + ' (' + dislikecount + ')'}</span></span>
                        </span>
                    </MenuItem>;
                }
            }
        }
    }
    return <MenuItem>
        <span
            onClick={() => {
                Search.doCustomButton(record, '', cb, '')
            }}
        >
            {isExitIcon ? <div className='cube-list-icon-box'>{cb.icon?<img src={cb.icon}/>:''}</div>:''}
            <span style={{ color: '#000' }}>{cb.text}</span>
        </span>
    </MenuItem>;
}

export const parserColumnsForShowList = (record, num, cb, index, isShowIcon, Search, listtype) => {
    let otherparas = cb.otherpara.split("+");
    let index1 = 0;
    for (index1; index1 < otherparas.length; index1++) {
        let islikebutton = otherparas[index1].replace("#islikebutton:", "");
        if (islikebutton && islikebutton == '1') {
            let likeinfo = otherparas[index1 + 1].replace("#likeinfo:", "")
            let type = likeinfo.split(",")[0];
            let status = likeinfo.split(",")[3];
            let likecount = likeinfo.split(",")[1];
            let dislikecount = likeinfo.split(",")[2];
            if (type == '5') {
                if (status == '1') {
                    return <Button type="ghost" onClick={() => {
                        Search.likeOrDislike(record, "0", index, listtype)
                    }}>
                        <span>
                            <i title={getLabel('31129', '取消') + cb.text} className={"icon-coms02-like"}/>
                            {isShowIcon ? <span title={cb.text || ''}>{'(' + likecount + ')'}</span> :
                                <span>{' ' + cb.text + '(' + likecount + ')'}</span>}
                        </span></Button>
                } else {
                    return <Button type="ghost" onClick={() => {
                        Search.likeOrDislike(record, "1", index, listtype)
                    }}>
                        <span>
                            <i title={cb.text} className={"icon-coms02-like-o"}/>
                            {isShowIcon ? <span title={cb.text || ''}>{'(' + likecount + ')'}</span> :
                                <span>{' ' + cb.text + ' (' + likecount + ')'}</span>}
                        </span></Button>
                }
            } else if (type == '6') {
                if (status == '2') {
                    return <Button type="ghost" onClick={() => {
                        Search.likeOrDislike(record, "0", index, listtype)
                    }}>
                        <span>
                            <i title={getLabel('31129', '取消') + cb.text} className={"icon-coms02-Negative-comment"}/>
                            {isShowIcon ? <span title={cb.text || ''}>{'(' + dislikecount + ')'}</span> :
                                <span>{' ' + cb.text + ' (' + dislikecount + ')'}</span>}
                        </span></Button>
                } else {
                    return <Button type="ghost" onClick={() => {
                        Search.likeOrDislike(record, "2", index, listtype)
                    }}>
                        <span>
                            <i title={cb.text} className={"icon-coms02-Negative-comment-o"}/>
                            {isShowIcon ? <span title={cb.text || ''}>{'(' + dislikecount + ')'}</span> :
                                <span>{' ' + cb.text + ' (' + dislikecount + ')'}</span>}
                        </span></Button>
                }
            }
        }
    }
    return <Button title={cb.text || ''} type="ghost" onClick={() => {
        Search.doCustomButton(record, '', cb, '')
    }}>
        {cb.icon ?
            <div className='cube-list-icon-box'><img src={cb.icon}/></div> : (!isShowIcon ? '' :
                <div className='cube-list-icon-box'><img src={'/mobilemode/piclibrary/01-E9_default/setup.png'}/>
                </div>)}
        {!isShowIcon ? cb.text : ''}
    </Button>
}


/****
 * 
 * 导出文件
 */

export const   getContent = (Search) => {
    const { progress } = Search;
    const step = progress.step;
    let content = "";
    if (!step) {
        return getLabel('508305', '正在导出文件');
    }
    if (step == 'start') {
        content = getLabel('508301', '正在进行导出准备');
    } else if (step == 'expSheet') {
        let total = parseInt(progress.sheetcount);
        if (total > 1) {
            content = `${getLabel('509502', '正在导出第{current}/{total}个sheet')} ,${getLabel('384158', '当前进度')} :${progress.current}/${progress.total}`;
            content = content.replace(/\{current\}/, progress.currsheet).replace(/\{total\}/, progress.sheetcount);
        } else {
            content = `${getLabel('384158', '当前进度')} ：${progress.current}/${progress.total}`;
        }
    } else if (step == 'createFile') {
        content = getLabel('508304', '正在创建文件');
    } else if (step == 'querydata') {
        content = getLabel('513078', '正在查询数据');
    } else if (step == 'zip') {
        content = getLabel('513077', '正在压缩文件');
    } else if (step == 'expcard') {
        content = getLabel('513076', '正在导出第{current}/{total}个文件');
        content = content.replace(/\{current\}/, progress.current).replace(/\{total\}/, progress.total);
    }
    return content;
}

   // 计算高级搜索面板最大值
   export const computeSearchAd = (Search) => {
    try {
        let domViewRes = jQuery('.coms-mode-viewResource .list-container');//资源面板
        if(domViewRes.length>0 && Search.viewResHeight){
            let tabHeight = domViewRes.find('.cube-list-wrapper .wea-tab').height() || 0;
            domViewRes.find('.cube-list-wrapper .wea-advanced-searchsAd').css('maxHeight',`${Search.viewResHeight - tabHeight - 62}px`)
        }
    } catch (error) {

    }
}

/***
 * mobxtableedit  计算滚动高度
 */
export const   getScroll = (Search) => {
    let width = 0, height = document.documentElement.clientHeight;
    Search.editTableStore.columns.map(column => {
        if (column.width) {
            if (typeof column.width === 'string') {
                if (column.width.indexOf('%') > -1) {
                    width += document.documentElement.clientWidth * parseFloat(column.width.replace('%', ''))
                } else {
                    width += parseFloat(column.width);
                }
            } else if (typeof column.width === 'number') {
                width += column.width;
            }
        } else {
            width += 100;
        }
    })
    return {
        x: width,
        y: height - 214
    }
}

/*****
 * 获取当前菜单布局
 * 计算顶部，左侧距离，滑动出来的需要
 */
export const getTopLeft = ()=>{
    const themelayoutType = (WeaTools.ls.getJSONObj('theme-themeInfo') && WeaTools.ls.getJSONObj('theme-themeInfo').themeLayoutType) || "1"; //门户布局
    let top = 0;
    if (themelayoutType == '1') { //默认布局
        top = jQuery(".e9theme-layout-main").offset() ? (jQuery(".e9theme-layout-main").offset().top ? jQuery(".e9theme-layout-main").offset().top + 10 : 0) : 0;
    } else {
        top = jQuery(`.e9theme-layout${themelayoutType}-main`).offset() ? (jQuery(`.e9theme-layout${themelayoutType}-main`).offset().top ? jQuery(`.e9theme-layout${themelayoutType}-main`).offset().top + 10 : 0) : 0;
    }
    if (top == 0) {
        top = jQuery(".e8theme-layout-main").offset() ? (jQuery(".e8theme-layout-main").offset().top ? jQuery(".e8theme-layout-main").offset().top + 10 : 0) : 0;
    }

    let left = jQuery(".e9theme-layout-main").offset() ? (jQuery(".e9theme-layout-main").offset().left ? jQuery(".e9theme-layout-main").offset().left + 10 : 0) : 0;
    if (left == 0) {
        left = jQuery(".e8theme-layout-main").offset() ? (jQuery(".e8theme-layout-main").offset().left ? jQuery(".e8theme-layout-main").offset().left + 10 : 0) : 0;
        if (left == 0) {
            left = jQuery(".cube-tree-list").css('width');
            if (left == undefined) {
                left = 0;
            } else {
                left = left.replace('px', '') - 14;
            }
        } else {
            let treeleft = jQuery(".cube-tree-list").css('width');
            if (treeleft == undefined) {
                treeleft = 0;
            } else {
                left = left + parseFloat(treeleft.replace('px', '')) - 10;
            }
        }
    } else {
        let treeleft = jQuery(".cube-tree-list").css('width');
        if (treeleft == undefined) {
            treeleft = 0;
        } else {
            left = left + parseFloat(treeleft.replace('px', '')) - 10;
        }
    }

    return {top,left}
}

/**
 * 判断自定义按钮是否存在图标
 * type: 'opt':操作"更多"  'customOpt':自定义按钮
 * custombtnArr: 下拉选项数组数据
 * filter: 过滤条件
 */
export const isExitIconHandle = (type, custombtnArr, filter?) => {
    if (type === 'opt') {
        if (custombtnArr) {
            return _.some(custombtnArr, item=>item.icon);
        }
        return true;
    } else if (type === 'customOpt') {
        const filterArr:any[] = filter.split('+');
        return _.some(custombtnArr, (item,index) => {
            if (filterArr[index] === 'true' && item.icon) {
                return true;
            }
            return false;
        });
    }
}
